package red.mlz.console.controller.file;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import red.mlz.module.module.file.FileService;
import red.mlz.module.utils.Response;

import java.io.IOException;

@RestController
@Slf4j
public class FileController {


    @Autowired
    private FileService fileService;
    /**
     * 文件上传
     */
    @RequestMapping("/file/upload")
    public Response upload(MultipartFile file) {
        log.info("文件上传: {}", file);
        String fullPath;
        try {
            fullPath = fileService.upload(file);
            log.info("文件上传成功,路径为: {}", fullPath);
        } catch (IOException e) {
            log.error("文件上传失败", e);
            throw new RuntimeException(e);
        }
        return new Response(1001);
    }
}
